package DataSourceOptimize;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class Text {
    public static void main(String[] args) {
        PreparedStatement statement =null;
        Connection connection=null;
        try {
            connection =MyConnection.connection();
            String sql ="insert into student (sn,name,mail,class_id) values (?,?,?,?)";
            statement = connection.prepareStatement(sql);
            Scanner scanner =new Scanner(System.in);
            System.out.println("请输入学号：");
            String sn =scanner.next();
            System.out.println("请输入姓名：");
            String name =scanner.next();
            System.out.println("请输入邮件：");
            String mail =scanner.next();
            System.out.println("请输入班级编号：");
            Long class_id =Long.valueOf(scanner.next());
            statement.setString(1,sn);
            statement.setString(2,name);
            statement.setString(3,mail);
            statement.setLong(4,class_id);
            int i = statement.executeUpdate();
            if (i==1){
                System.out.println("插入成功.....");
            }else {
                System.out.println("插入失败.....");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            MyConnection.close(connection,statement,null);
        }
    }
}
